#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<sys/stat.h>
#include<stdlib.h>
#include<sys/mman.h>
#include<stdio.h>
#include<errno.h>
int main(int argc,char** argv)
{

    int fd;
   typedef  struct student
   {
       int num;
       char* name;
       char sex;
       }stu;
    
    fd=open("consanguinity.txt",O_RDWR|O_CREAT|O_TRUNC);

    if(fd>0)
    {
        perror("open fail!\n");
        }

    //该进程向mmap区域写结构体
//    stu st={20,"zhangsan",'M'};

    //向consanguinity.txt中进行扩容
  //  lseek(fd,40,SEEK_END);
   // write(fd,"\0",1);

   // int size=lseek(fd,0,SEEK_END);
     //创建映射区域
     stu st;
     stu *p=(stu*)mmap(NULL,sizeof(st),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);

    // stu st;
     if(p==MAP_FAILED)
     {
         
         perror("mmap fail!\n");

        }

        //从mmap读取数据结构
//        memcpy(&st,p,sizeof(st));

        while(1)
        {
            
           printf("student:num:%d,name:%s,sex:%c\n",st.num,st.name,st.sex);
          sleep(1);
          
            }
      // printf("student:num:%d,name:%s,sex:%c\n",st.num,st.name,st.sex);

        close(fd);



return 0;
}
